package com.sjzs.web.dao;

import java.util.Date;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sjzs.web.po.Attach;
import com.sjzs.web.util.DateUtil;

public class AttachDao extends HibernateDaoSupport {
	/**
	 * 根据关联guid获取附件信息
	 * @param linkguid
	 * @return
	 */
	public Attach getAttachByLinkguid(String linkguid) {
		List<Attach> lstAttachs = this.getHibernateTemplate().find(
				"from Attach where 1=1 and linkguid = ?", linkguid);
		if(lstAttachs == null){
			return null;
		}else{
			return lstAttachs.get(0);
		}
	}
	
	public void saveAttach(Attach attach){
		String id=this.getSession().createSQLQuery("select SEQ_ATTACH_ID.nextval from dual").uniqueResult().toString();
		attach.setId(id);
		attach.setCreatedate(DateUtil.dateToString("yyyy-MM-dd HH:mm:ss", new Date()));
		this.getHibernateTemplate().save(attach);		
	}
}
